<?php
namespace Admin\Controller;


class IndexController extends AdminController {
    protected function checkUser(){
        if(!isset($_SESSION[C("USER_AUTH_KEY")])){
            $this->error("没有登录","login");
        }
    }
    
    public function menu(){
        $this->checkUser();
        $menu = getSysMenu();
        //缓存菜单访问
        session("menu".session(C('USER_AUTH_KEY')),$menu);
        $this->assign("menu",$menu);
        $this->display();
    }
    
    
    public function index(){
//        var_dump(session('ru'));exit;
        if(session('ru')){
            if(isCs()){
                $this->redirect('Service/Center/index');
            }
        }
        $this->display();
    }
    
    public function login(){
        $this->display();
    }
    public function oauth(){
        $username = I("get.username");
        $password = I("get.password");
        $ANI = I("get.ANI");
        $userLoginDao = D("UserLogin");
        $ret = $userLoginDao->oauth($username,md5($password));
        $this->redirect("Service/Center/index",array("tel" => $ANI));
    }

    public function checkLogin(){
        if(IS_POST)
        {       
            $username = I("post.username");
            $password = I("post.password","","md5");
            $userLoginDao = D("UserLogin");
            if($userLoginDao->create()){
                $ret_data = $userLoginDao->login($username,$password);;
            }else{
                //获取到错误数据
               $ret_data = array();
               $err1 = $userLoginDao->getError();
               foreach ($err1 as $key => $value) {
                   $ret_data['sign'] = $value;
                   break;
               }  
               $ret_data['status'] = 0;
            }
            $this->ajaxReturn($ret_data);
        }
        else
        {
            $this->error("非法访问");
        }
    }
    
    public function loginOut(){
        if(session(C('USER_AUTH_KEY'))){
            session(C('USER_AUTH_KEY'),null);
            session(null);
            session('[destroy]');
            $this->success('登出成功！',U("login"));
        }else{
            $this->error('已经登出！',U("login"));
        }
    }
    
    public function welcome(){
        $this->display();
    }
    
    public function verifyCode(){
        $config = array(
                'useNoise'    =>  true,
                'length' 	=> 4,
                'fontSize'	=> 15,
                'imageW' => 115,
                'imageH' => 34,
                'codeSet'	=>   '0123456789',
        );
		ob_clean();
        $Verify = new \Think\Verify($config);
        $Verify->entry();
    }


}